package com.acme.clientside;

import java.io.ObjectInputStream;

class ServerConnection implements Runnable {

    public static final String EXIT = "<exit>";

    final Thread thread;
    private final ObjectInputStream inputStream;

    public ServerConnection(ObjectInputStream inputStream) {
        this.inputStream = inputStream;
        this.thread = new Thread(this);
    }

    @Override
    public void run() {
        try {
            String message;
            do {
                message = (String) this.inputStream.readObject();
                if (!message.equals(EXIT))
                    System.out.printf("%s", message);
            } while (!message.equals(EXIT));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
